package com.hk.commons.utils.sys;


import java.util.ArrayList;
import java.util.List;

/**
 * Created by jeff on 2017/1/9.
 */
public class ListHelper<T> {

    /*
    获取产品列表
     */
    public List<T> page(int pageNo, int pageSize, List<T> list) throws Exception{
        List<T> result = new ArrayList<T>();
        if(list != null && list.size() > 0){
            int allCount = list.size();

            int pageCount = (allCount + pageSize-1) / pageSize; //总页数

            if(pageNo >= pageCount){
                pageNo = pageCount;
            }
            int start = pageNo * pageSize;

            int end = start +  pageSize;

            if(end >= allCount){
                end = allCount;
            }
            for(int i = start; i < end; i ++){
                result.add(list.get(i));
            }
        }
        return (result != null && result.size() > 0) ? result : null;
    }
}
